package com.ldpp.backengine;

import com.ldpp.entity.TickMin;
import com.lmax.disruptor.RingBuffer;

/**
 * @author ：gongtan
 * @date ：Created in 2021/3/16 13:39
 * @description：
 * @modified By：
 */
public class BackProducer {

    private RingBuffer<TickMin> ringBuffer;

    //构造
    public BackProducer(RingBuffer<TickMin> ringBuffer){
        this.ringBuffer = ringBuffer;
    }

    public void onData(TickMin tick){
        //拿到环形的序列位置 (下标位置)
        long sequence = ringBuffer.next();
        try {
            //取出 空队列（Event）
            TickMin tickMin = ringBuffer.get(sequence);
            //给空队列项 赋值
            tickMin.setClose(tick.getClose());
            tickMin.setOpen(tick.getOpen());
            tickMin.setCreateTime(tick.getCreateTime());
            tickMin.setExchange(tick.getExchange());
            tickMin.setHigh(tick.getHigh());
            tickMin.setLow(tick.getLow());
            tickMin.setInterval(tick.getInterval());
            tickMin.setWindCode(tick.getWindCode());
        }catch (Exception e){
            // TODO ：handle Exception
        }finally {
           // System.out.println("event生产者发送数据");
            //发送数据
            ringBuffer.publish(sequence);
        }

    }
}
